﻿'Title:     Alphabetizing Words Lab
'Author:    Greg Cronk
'Date:      02/18/2014
'Course:    CSC 162
'Section:   
'Description:   This program allows the user to enter 2 strings and compares them to determine which comes first alphabetically.
'
'Initial Algorithm:
'   1.  Get 2 words From user
'   2.  Assure the entries are not numbers
'   3.  Compare first and second word
'   4.  Determine if they are the same word or if not which one comes first alphabetically
'   5.  Display the results.
'
'Data Requirements:
'   Input:
'       Words entered by user. firstWord and secondWord
'   Output:
'       Words listed by alphabetical order
'   Additional:
'       **Done optionally by myself** Compares to assure they are not the same word
'         Takes into account letter case by forcing the program to treat all letters entered as lower case.
'         Checks to make sure the entered data starts with a letter and not a number.
'
'Formulas:
'   firstWord > secondWord
'   firstWord = secondWord
'
'Refine Algorith In Subs as used.


Public Class frmAlphabet
   
    Private Sub btnExit_Click(sender As System.Object, e As System.EventArgs) Handles btnExit.Click

        'Close the Form Window and Release the Memory Space
        Me.Close()
        End

    End Sub

    Private Sub btnClear_Click(sender As System.Object, e As System.EventArgs) Handles btnClear.Click

        'Clear the Contents of the Output Box
        'Set the Alphabetize button as the focus
        txtOutput.Text = String.Empty
        btnAlphabet.Focus()

    End Sub

    Private Sub btnAlphabet_Click(sender As System.Object, e As System.EventArgs) Handles btnAlphabet.Click
        'Declare Varibles
        'Reserve memory Space for our Input Box windows, their labels and titles

        Dim msgTitleA As String
        Dim msgTitleB As String
        Dim MessageA As String
        Dim MessageB As String

        'Reserve memory Space for the two words entered by the User.

        Dim secondWord As String
        Dim firstWord As String

        'Generate Format for the Input Box for the First Word

        MessageA = "Enter the first word into the Input Box and Click OK"
        msgTitleA = "Word Entry"

        'Generate Format for the Input Box for the Second Word

        MessageB = "Enter the second word into the Input Box and Click OK"
        msgTitleB = "Word Entry"

        'Display the input box windows
        'Set the entered Strings (words) as the values of firstWord and secondWord

        firstWord = InputBox(MessageA, msgTitleA)
        secondWord = InputBox(MessageB, msgTitleB)

        If IsNumeric(firstWord.ToLower) Then

            'Check to see if the user entered numeric values into the text box and if so reject the results.

            Dim messageReplyNumeric1 As String
            messageReplyNumeric1 = MsgBox("Please enter only Non-Numeric Characters and Try again.")
            btnAlphabet.Focus()

        ElseIf IsNumeric(secondWord.ToLower) Then

            'Check to see if the user entered numbers into the text box and if so reject the results.

            Dim messageReplyNumeric2 As String
            messageReplyNumeric2 = MsgBox("Please enter only Non-Numeric Characters and Try again.")
            btnAlphabet.Focus()

        ElseIf firstWord.ToLower = secondWord.ToLower Then

            'Begin the Comparisons of different words.
            'Check to see if the same word is entered both times. 
            'Use ".ToLower" to Treat the entered words to Lower Case for accurate comparison.
            'Assure the Values are the same 
            'If they are send back a message popup asking the user to enter two different words.
            'If they Values are not the same then go on to the next ElseIf

            Dim messageReply As String
            messageReply = MsgBox("Those are the same words, please try again with two different words.")
            btnAlphabet.Focus()

        ElseIf firstWord.ToLower < secondWord.ToLower Then


            'Use ".ToLower" to Treat the entered words to Lower Case for accurate comparison. 
            'Set the output if the first word entered comes first alphabetically and display it in the Output Box
            'If the value of the secondWord is < the value of firstWord then go to the final option
            'Set the Clear Button as the focus to prepare the user for the next set of entries

            txtOutput.Text = "Alphabetically the first word is " & firstWord & ControlChars.NewLine _
                & "The second word Alphabetically is " & secondWord
            btnClear.Focus()

        Else

            'Our last alternative is for the second word to be first Alphabetically 
            'Use ".ToLower" to Treat the entered words to Lower Case for accurate comparison. 
            'set the output if the second word comes first alphabetically and display it in the Output box
            'Set the Clear Button as the fous to prepare the user for the next set of entries

            txtOutput.Text = "Alphabetically the first word is " & secondWord & ControlChars.NewLine _
                & "The second word Alphabetically is " & firstWord
            btnClear.Focus()

        End If

    End Sub

End Class
